//
//  LSTeamHandicapViewController.m
//  LookScore
//
//  Created by wr on 2018/4/20.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSTeamHandicapViewController.h"
#import "UIViewController+ZJScrollPageController.h"

#import "LSPulldDownOptionsView.h"//下拉view
#import "LSTeamDetailCell.h"

@interface LSTeamHandicapViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(strong,nonatomic)UITableView *tableView;

@property(strong,nonatomic)LSPulldDownOptionsView *pullView;

@property(strong,nonatomic)UIButton *categoryBu;

@end

@implementation LSTeamHandicapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
}

-(void)zj_viewDidLoadForIndex:(NSInteger)index{
    self.tableView.tableHeaderView = [self tableHeadView];
    [self.view addSubview:self.tableView];
    
    //    [self loadTeamHandicapData];
}
- (void)loadTeamHandicapData{
    
    //    MyLog(@"leagueId --- %@ /n season --- %@",self.leagueId,self.season);
    [LSHttpEnclosureTool GET:LSLeagueIntegral parameters:@{@"leagueId":@"36",@"matchSeason":@"2017-2018"} resBlock:^(id responseObject) {
        if (responseObject) {
            MyLog(@"leagueTable ---- %@",responseObject);
        }
    }];
}
#pragma mark 🔥 Event

-(void)chooseCategoryEvent:(UIButton *)sender{
    
    NSArray * dataArray = @[@"2017-2018英超",@"2016-2017英超",@"2015-2016英超",@"2014-2015英超"];
    
    NSMutableArray *array = dataArray.mutableCopy;
    if (!self.pullView) {
        LSPulldDownOptionsView *pullView=[[LSPulldDownOptionsView alloc]initWithFrame:CGRectMake(0, 0, LSScreenWidth, LSScreenHeight) normalTitleColor:LSNavMainDarkColor selectedTitleColor:LSTitleWhiteColor normalBackViewColor:LSTitleWhiteColor selectedBackViewColor:LSNavMainDarkColor height:35];
        
        pullView.modelArray=array.mutableCopy;
        pullView.cellClickBlock = ^(NSInteger index) {
            [self.categoryBu setTitle:array[index] forState:UIControlStateNormal];
            
            
        };
        self.pullView=pullView;
        [self.view addSubview:pullView];
    }
    self.pullView.hidden=NO;
    
}

#pragma mark 🔥 tableViewDelegate tableViewDataSource
-(UIView *)tableHeadView{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LSScreenWidth, 32)];
    view.backgroundColor = [UIColor whiteColor];
    
    
    UIButton *categoryBu=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, LSScreenWidth, 32)];
    //    categoryBu.backgroundColor = [UIColor redColor];
    [categoryBu setTitleColor:LSTitleGrayColor1 forState:UIControlStateNormal];
    categoryBu.titleLabel.font = LSFontSize12;
    [categoryBu setTitle:@"2017-2018英超" forState:UIControlStateNormal];
    [categoryBu setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [view addSubview:categoryBu];
    //    navigetionBu.titleEdgeInsets=UIEdgeInsetsMake(0,-50, 0, 50);
    //    navigetionBu.imageEdgeInsets=UIEdgeInsetsMake(0, 60, 0, -60);
    [categoryBu addTarget:self action:@selector(chooseCategoryEvent:) forControlEvents:UIControlEventTouchUpInside];
    self.categoryBu = categoryBu;
    
    return view;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 9;
    }else{
        return 3;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 35;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return 75;
    }
    else{
        return 43;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LSScreenWidth, 45)];
    headerView.backgroundColor = LSBackGroundColor;
    if (section == 0) {
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = [UIColor whiteColor];
        [headerView addSubview:whiteView]; whiteView.sd_layout.leftEqualToView(headerView).topEqualToView(headerView).offset(9).rightEqualToView(headerView).bottomEqualToView(headerView);
        
        
        NSInteger width = (LSScreenWidth - 40)/4;
        NSArray *array = @[@"类别",@"主场",@"客场",@"全部"];
        for (int i = 0; i < 4; i ++) {
            UILabel *lable = [UILabel new];
            lable.text = array[i];
            lable.textColor = LSTitleGrayColor3;
            lable.font=LSFontSize12;
            [whiteView addSubview:lable];
            lable.sd_layout.leftEqualToView(whiteView).offset(20+i*width).topEqualToView(whiteView).widthIs(width).heightIs(34);
        }
    }
    if (section == 1) {
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = [UIColor whiteColor];
        [headerView addSubview:whiteView]; whiteView.sd_layout.leftEqualToView(headerView).topEqualToView(headerView).offset(9).rightEqualToView(headerView).bottomEqualToView(headerView);
        
        UILabel *titleLable = [[UILabel alloc] init];
        titleLable.text = @"盘路详情";
        titleLable.font = LSFontSize13;
        titleLable.textColor = LSSubColor5D5D5D;
        [headerView addSubview:titleLable];
        titleLable.sd_layout.leftEqualToView(whiteView).offset(30).topEqualToView(whiteView).widthIs(80).heightIs(34);
        
        UIView *greanLine = [[UIView alloc] init];
        greanLine.backgroundColor = LSNavMainColor;
        [headerView addSubview:greanLine];
        greanLine.sd_layout.leftEqualToView(whiteView).offset(20).centerYEqualToView(titleLable).widthIs(2).heightIs(15);
        
        
        
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = LSLineGrayColor;
        [whiteView addSubview:lineView];
        lineView.sd_layout.leftEqualToView(whiteView).topEqualToView(whiteView).offset(titleLable.height).rightEqualToView(whiteView).heightIs(0.5);
        
        NSInteger width = (LSScreenWidth - 20)/6;
        NSArray *array = @[@"比赛时间",@"盘口",@"主",@"比分",@"客",@"盘路"];
        for (int i = 0; i < 6; i ++) {
            UILabel *lable = [UILabel new];
            lable.text = array[i];
            lable.textColor = LSTitleGrayColor3;
            lable.font=LSFontSize12;
            lable.textAlignment = NSTextAlignmentCenter;
            [whiteView addSubview:lable];
            lable.sd_layout.leftEqualToView(whiteView).offset(10+i*width).topEqualToView(lineView).widthIs(width).heightIs(34);
            
//            if (i==0) {
//                lable.sd_layout.leftEqualToView(greanLine).topEqualToView(lineView).widthIs(width).heightIs(34);
//                lable.textAlignment = NSTextAlignmentLeft;
//            }else if (i==1){
//                lable.sd_layout.leftEqualToView(whiteView).offset(width+20).topEqualToView(lineView).widthIs(95).heightIs(34);
//                lable.textAlignment = NSTextAlignmentRight;
//            }else if (i==2){
//                lable.sd_layout.leftEqualToView(whiteView).offset(width+115).topEqualToView(lineView).widthIs(width).heightIs(34);
//                lable.textAlignment = NSTextAlignmentCenter;
//            }else if (i==3){
//                lable.sd_layout.leftEqualToView(whiteView).offset(width*2+115).topEqualToView(lineView).widthIs(95).heightIs(34);
//                lable.textAlignment = NSTextAlignmentLeft;
//            }else if (i==4){
//                lable.sd_layout.rightEqualToView(whiteView).offset(-20).topEqualToView(lineView).widthIs(width).heightIs(34);
//                lable.textAlignment = NSTextAlignmentRight;
//            }
            
        }
    }
    return headerView;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        LSTeamDetailCell *cell=[LSTeamDetailCell TeamDetailCellByTableView:tableView];
        if (indexPath.row % 2 == 0) {
            cell.backgroundColor = LSSubGrayColorf7;
        }
        else{
            cell.backgroundColor = [UIColor whiteColor];
        }
        return cell;
    }else{
        LSTeamDishRoadDetailCell *cell=[LSTeamDishRoadDetailCell TeamDishRoadDetailCellByTableView:tableView];
        if (indexPath.row % 2 == 0) {
            cell.backgroundColor = LSSubGrayColorf7;
        }
        else{
            cell.backgroundColor = [UIColor whiteColor];
        }
        return cell;
    }
    
    
}
#pragma mark 🔥 Getter
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, LSScreenWidth, LSScreenHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.sectionHeaderHeight = 10;
        _tableView.sectionFooterHeight = 0;
        _tableView.backgroundColor =LSBackGroundColor;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

@end


